<template>
  <div id="app">
    <keep-alive>
      <router-view v-if="$route.meta.keepAlive"></router-view>
    </keep-alive>
    <router-view v-if="!$route.meta.keepAlive"></router-view>
  </div>
</template>

<script>
import zhCN from "ant-design-vue/lib/locale-provider/zh_CN";

export default {
  name: "App",
  data() {
    return {
      locale: zhCN
    };
  },
  methods: {
    /** 在刷新和关闭之前询问 **/
    beforeRefreshClose() {
      let self = this;
      // 监听路由内需要；浏览器提示的页面
      const arr = [
        "/picking/wareOrder",
        "/order/add",
        "/order/edit",
        "/product/child"
      ];
      window.onbeforeunload = function(e) {
        if (arr.indexOf(self.$route.path) > -1) {
          e = e || window.event;
          // 兼容IE8和Firefox 4之前的版本
          if (e) e.returnValue = "关闭提示1";
          // Chrome, Safari, Firefox 4+, Opera 12+ , IE 9+
          return "关闭提示2";
        } else window.onbeforeunload = null;
      };
    }
  },
  mounted() {
    this.beforeRefreshClose();
  }
  /*mounted: function () {
      //此方法刷新页面时也会执行
      window.addEventListener('beforeunload',() => {
        localStorage.removeItem('value');
      })
    }*/
};
</script>

<style lang="less" scoped>
#app {
  width: 100%;
  height: 100%;
}
</style>
